import logging

import allure
from selenium.webdriver.common.by import By

from ding.LitemallPrac.page_objects.base_page import BasePage
from ding.LitemallPrac.page_objects.product_list_page import ProductListPage


class ProductLaunchPage(BasePage):
    _INPUT_PRODUCT_CODE =(By.XPATH,"//label[@for='goodsSn']/../div/div/input")
    _INPUT_PRODUCT_NAME =(By.XPATH,"//label[@for='name']/../div/div/input")
    _INPUT_PRODUCT_PRICE =(By.XPATH,"//label[@for='counterPrice']/../div/div/input")
    _RADIO_HOT =(By.XPATH,"//span[contains(text(),'热卖')]")
    _Button_launch =(By.XPATH,"//div[@class='op-container']//span[contains(text(), '上架')]")
    #商品上架
    with allure.step("商品上架"):
        def product_launch(self):
            # 输入商品编号
            logging.info("输入商品编号")
            self.do_send_keys("12312415", *self._INPUT_PRODUCT_CODE)
            # 输入商品名称
            logging.info("输入商品名称")
            self.do_send_keys("Hogwarts", *self._INPUT_PRODUCT_NAME)
            # 输入市场售价
            logging.info("输入市场售价")
            self.do_send_keys("666", *self._INPUT_PRODUCT_PRICE)
            # 点击热卖按钮
            logging.info("点击热卖按钮")
            self.do_click(*self._RADIO_HOT)
            # 滑动到页面底部
            logging.info("滑动到也页面底部")
            self.driver.execute_script("window.scroll(0,document.body.scrollHeight)")
            # 点击上架按钮
            logging.info("点击上架按钮")
            self.do_click(*self._Button_launch)


            return ProductListPage(self.driver)


